package com.qfedu.aunt.commons.controller;


import com.qfedu.aunt.commons.result.R;
import com.qfedu.aunt.commons.service.PermService;
import com.qfedu.aunt.commons.vo.MenuShowVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaobobo
 * @since 2022-10-31
 */
@RestController
@RequestMapping("/aunt/commons/perm")
@Api(description = "菜单模块",tags = "菜单模块")
public class PermController {

    @Autowired
    private PermService permService;


    /**
     * 获取所有菜单弄成树形结构
     * @return
     */
    @GetMapping("/findMenuAll")
    @ApiOperation(value = "获取所有菜单弄成树形结构")
    @ApiImplicitParam(name = "token",value = "用户身份标识",dataType = "string",paramType = "header",required = true)
    public R findMenuAll(){
        //查询所有菜单弄成树形结构
        List<MenuShowVo> menuShowVos=permService.findMenuAll();
        //这里直接将我们的一级分类的id弄出来
        List<String> ids=new ArrayList<>();
        menuShowVos.get(0).getChildren().stream().forEach(m->{
            ids.add(m.getPermId());
        });
        return R.ok().setData("menuList",menuShowVos).setData("showId",ids);

    }

}

